/* 
 * gdp排名情况
 * gdpRanking(p) p=>参数
 */
function gdpRanking(p) {
    var arr1 = [];   // x轴数据
    var arr2 = [];   //完成值数据
    var arr3 = [];   //增长率数据
    for (var i = 0; i < p.length; i++) {
        arr1.push(p[i].area);
        arr2.push(p[i].cumulative);
        arr3.push(p[i].ratio);
    }
    var option = {
        tooltip: {
            trigger: 'axis',
            // formatter: "{b} : {c} </br> {b1} : {c1}",
            axisPointer: {
                // 坐标轴指示器，坐标轴触发有效
                type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            left: '0%',
            right: '0%',
            bottom: '8%',
            containLabel: true
        },
        legend: {
            x: "center",
            y: "10%",
            data: ['完成值(亿元)', '增长率(%)'],
            textStyle: {
                color: '#fff',
                fontSize: '12',
            }
        },
        xAxis: [{
            type: 'category',
            data: arr1,
            axisPointer: {
                type: 'shadow'
            },
            axisLabel: {
                interval: 0,//x轴数值全部显示出来
                rotate: -30,//设置角度
                show: true,
                textStyle: {
                    color: '#fff',
                    fontSize: 10 //设置x轴字体
                }
            },
            axisLine: {
                lineStyle: {
                    color: '#fff',
                    width: 1, //这里是为了突出显示加上的
                }
            },
        }],
        yAxis: [{
            type: 'value',
            name: '亿元',
            // min: 0,
            // max: 250,
            // interval: 50,
            axisLabel: {
                formatter: '{value} '
            },
            axisLine: {
                lineStyle: {
                    color: '#fff',
                    width: 1, //这里是为了突出显示加上的
                }
            },
            //去掉网格线
            splitLine: {
                show: false
            },

        },
            {
                type: 'value',
                name: '比率 (%)',
                // min: 0,
                // max: 25,
                // interval: 5,
                axisLabel: {
                    formatter: '{value} '
                },
                axisLine: {
                    lineStyle: {
                        color: '#fff',
                        width: 1, //这里是为了突出显示加上的
                    }
                },
                //去掉网格线
                splitLine: {
                    show: false
                },
            }
        ],
        series: [{
            animationDuration: 5000,
            name: '完成值(亿元)',
            type: 'bar',
            data: arr2
        },
            {
                animationDuration: 3000,
                name: '增长率(%)',
                type: 'line',
                yAxisIndex: 1,
                data: arr3,
                type: "line",
                symbol: "circle", //设定为实心点
                symbolSize: 12, //设定实心点的大小
                itemStyle: {
                    normal: {
                        color: "#2194FF", //小圆点颜色
                        lineStyle: {
                            color: "#2194FF", //折线颜色
                            width: 3
                        }
                    }
                }

            }
        ],
        color: ["#6FFFC0"],
        barWidth: 15
    };


    //基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('gdpRanking'));
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
    //自适应大小
    window.addEventListener("resize", function () {
        myChart.resize();
    });
}

/* 
 * 第三产业增幅中七大指标贡献比
 */

function growthContribution(data1, data2) {
    var arr = data1;//必须重新变量定义    formatte 函数才能使用
    var option = {
        tooltip: {
            trigger: "item",
            formatter: function (params) {
                var names = params.data.name;
                for (var i = 0; i < arr.length; i++) {
                    if (names == arr[i].indexName) {
                        return names + '\n' + '\n增长：' + (arr[i].increase == undefined ? "-" : arr[i].increase) + ' %\n' + '\n贡献：' + (arr[i].contribution == undefined ? "-" : arr[i].contribution) + ' %\n';
                    }
                }

            },
        },
        title: {
            text: '三产增幅',
            textStyle: { //设置主标题样式
                fontWeight: 'normal',
                fontSize: 14,
                color: '#fff' //#075689
            },
            subtext: data1[0].increase + ' %',
            subtextStyle: { //设置副标题样式
                color: '#32B4F6',
                fontSize: '18' //#075689
            },
            x: 'center',
            y: 'center',
        },
        series: [{
            animationDuration: 5000,
            name: '三产增幅',
            type: 'pie',
            radius: ['30%', '55%'],
            center: ['50%', "50%"], //移动圆位置
            label: {
                normal: {
                    formatter: function (params) {
                        var names = params.data.name;
                        for (var i = 0; i < arr.length; i++) {
                            if (names == arr[i].indexName) {
                                return names + '\n' + '\n增长：' + (arr[i].increase == undefined ? "-" : arr[i].increase) + ' %\n' + '\n贡献：' + (arr[i].contribution == undefined ? "-" : arr[i].contribution) + ' %\n';
                            }
                        }
                    },
                },
                fontSize: 15,
                color: "#fff",

            },
            labelLine: {
                show: true,
                length: 10
            },
            data: data2,
            color: ['#E56C6C', '#6CD6E8', '#C64DFF', '#7FD65B', "#FFCC5A", "#6DE2AB", "#E5896C"],
        }],
    };
    //基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('growthContribution'));
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
    //自适应大小
    window.addEventListener("resize", function () {
        myChart.resize();
    });
}

/*growthContribution();*/

$(function () {
    $.ajax({
        url: "/web/aiReport/dealReport",
        type: "POST",
        dataType: "json", //返回数据形式为json
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify({"date": ""}),
        success: function (res) {
            if (res.code == "200") {
                var item = res.data;
                //目标指标一
                var html1 = "";
                for (var i = 0; i < item.fightComplete.length; i++) {
                    var arr = item.fightComplete[i];
                    html1 += '\
                            <dl>\
                                <dt class="hidden-font" title="' + arr.industryName + '">' + arr.industryName + '</dt>\
                                <dt>' + arr.ratio + '%</dt>\
                                <dd>争先目标：' + arr.fightIncrease + '%</dd>\
                            </dl>\
                        ';
                }
                $(".target-1>.clear").html(html1);

                //目标指标二
                var html2 = "";
                for (var i = 0; i < item.countyComplete.length; i++) {
                    var arr = item.countyComplete[i];
                    html2 += '\
                            <dl>\
                                <dt class="hidden-font" title="' + arr.industryName + '">' + arr.industryName + '</dt>\
                                <dt class="green">' + arr.ratio + '%</dt>\
                                <dd>争先目标：' + arr.fightIncrease + '%</dd>\
                            </dl>\
                        ';
                }
                $(".target-2>.clear").html(html2);

                //目标指标三
                var html3 = "";
                for (var i = 0; i < item.cityComplete.length; i++) {
                    var arr = item.cityComplete[i];
                    html3 += '\
                            <dl>\
                                <dt class="hidden-font" title="' + arr.industryName + '">' + arr.industryName + '</dt>\
                                <dt class="yellow">' + arr.ratio + '%</dt>\
                                <dd>县级目标：' + arr.countyIncrease + '%</dd>\
                            </dl>\
                        ';
                }
                $(".target-3>.clear").html(html3);

                //目标指标四
                var html4 = "";
                for (var i = 0; i < item.noComplete.length; i++) {
                    var arr = item.noComplete[i];
                    html4 += '\
                            <dl>\
                                <dt class="hidden-font" title="' + arr.industryName + '">' + arr.industryName + '</dt>\
                                <dt class="red">' + arr.ratio + '%</dt>\
                                <dd>市级目标：' + arr.ciyIncrease + '%</dd>\
                            </dl>\
                        ';
                }
                $(".target-4>.clear").html(html4);


                var htmls='\
                    <div align="center">暂无数据</div>\
                    ';
                if (item.gdpRank.length !== 0) {
                    gdpRanking(item.gdpRank);//gdp排名
                }else{
                    $("#gdpRanking").html(htmls);
                }

                if (item.contribution.length !== 0 && item.conMap !== 0) {
                    growthContribution(item.contribution, item.conMap);//贡献占比
                }else{

                    $("#growthContribution").html(htmls);
                }


                // 末三名指标
                var rankHtml = "";
                for (var i = 0; i < item.rank3.length; i++) {
                    var data = item.rank3[i];
                    rankHtml += '\
                             <div class="row no-margin">\
                                <p class="red-left-border">\
                                    ' + data.industryName + '：第 <em>' + data.rank + '</em> 名\
                                </p>\
                                <div class="col-xs-6">\
                                    <p>累计值：' + data.cumulative + '亿元</p>\
                                </div>\
                                <div class="col-xs-6">\
                                    <p>增长率：' + data.ratio + '%</p>\
                                </div>\
                             </div>\
                        ';
                }
                $("#afterThree").html(rankHtml);

                var times = item.date;//报告时间
                var year = times.substring(0, 4);//年份
                var month = times.substring(4, 6);//月份

                //iframe  给父页面传值
                $(".title-container>p.box-title", top.document).html(year + "年" + month + "月永泰经济大数据-智能分析报告");
                $(".title-container>p.box-title", top.document).attr("title", $(".title-container>p.box-title", top.document).html());
            }
        }
    });
});